﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_FIM_Receives : IBLL_FIM_Receives
    {
        Common common = new Common();
        private static readonly IDAL_FIM_Receives dal = DataAccess.Create_FIM_Receives();
        //D_FIM_MAS_Receives r = new D_FIM_MAS_Receives();

        public B_FIM_Receives()
        {

        }

        public IList<M_FIM_Receives> GetFull(string bgm_source_seq, string work_area_seq, string bgm_year)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            return dal.GetFull(nbgm_source_seq, nwork_area_seq, nbgm_year);
        }

        public IList<M_FIM_Receives> GetFull(string bgm_source_seq, string work_area_seq, string bgm_year, string receive_mode)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> nreceive_mode = common.ConvertNullInt(receive_mode);

            return dal.GetFull(nbgm_source_seq, nwork_area_seq, nbgm_year, nreceive_mode);
        }
        public DataTable GetFullPrepare(string bgm_source_seq, string work_area_seq, string bgm_year, string source, string receive_seq)
        {
            return dal.GetFullPrepare(bgm_source_seq, work_area_seq, bgm_year, source, receive_seq);
        }

        public IList<M_FIM_Receives> GetNotDeposits(string bgm_source_seq, string work_area_seq
            , string bgm_year, string transfer_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> ntransfer_seq = common.ConvertNullInt(transfer_seq);
            return dal.GetNotDeposits(nbgm_source_seq, nwork_area_seq, nbgm_year, ntransfer_seq);
        }

        public IList<M_FIM_Receives> GetPayments(int pay_seq)
        {
            return dal.GetPayments(pay_seq);
        }

        public IList<M_FIM_Receives> GetNotPayments(string bgm_source_seq, string work_area_seq
            , string bgm_year, string pay_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
            return dal.GetNotPayments(nbgm_source_seq, nwork_area_seq, nbgm_year, npay_seq);
        }

        public IList<M_FIM_Receives> GetNotPaymentBacks(string bgm_source_seq, string work_area_seq
            , string bgm_year, string pay_seq)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            Nullable<int> npay_seq = common.ConvertNullInt(pay_seq);
            return dal.GetNotPaymentBacks(nbgm_source_seq, nwork_area_seq, nbgm_year, npay_seq);
        }

        public IList<M_FIM_Receives> GetList(string bgm_source_seq, string work_area_seq, string bgm_year)
        {
            Nullable<int> nbgm_source_seq = common.ConvertNullInt(bgm_source_seq);
            Nullable<int> nwork_area_seq = common.ConvertNullInt(work_area_seq);
            Nullable<int> nbgm_year = common.ConvertNullInt(bgm_year);
            return dal.GetList(nbgm_source_seq, nwork_area_seq, nbgm_year);
        }

        //public string SelectRecentInsertedRoleSeq()
        //{
        //    return dal.SelectRecentInsertedRoleSeq();
        //}

        public DataTable Report_Receipt(string seq)
        {
            int nSeq;

            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.Report_Receipt(nSeq);
            }
            else
            {
                return null;
            }
        }

        public DataTable Report_SumUpReceive(string date)
        {
            Nullable<DateTime> ndate = common.ConvertNullDateTime(date);
            return dal.Report_SumUpReceive(ndate);
        }

        public DataTable Report_SumUpReceiveFT(string dateFrom, string dateTo, string bgm_source)
        {
            Nullable<DateTime> ndateFrom = common.ConvertNullDateTime(dateFrom);
            Nullable<DateTime> ndateTo = common.ConvertNullDateTime(dateTo);
            return dal.Report_SumUpReceiveFT(ndateFrom, ndateTo, bgm_source);
        }

        public M_FIM_Receives GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public M_FIM_Receives GetInfoFromPetition(string petition_seq)
        {
            int nSeq;

            if (petition_seq == null)
                return null;

            if (common.IsNumeric(petition_seq))
            {
                nSeq = int.Parse(petition_seq);
                return dal.GetInfoFromPetition(nSeq);
            }
            else
            {
                return null;
            }
        }

        public string Insert(M_FIM_Receives info)
        {
            try
            {
                return dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_FIM_Receives info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_FIM_Receives info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateGlTranSeq(M_FIM_Receives info)
        {
            try
            {
                dal.UpdateGlTranSeq(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateDepositSeq(M_FIM_Receives info)
        {
            try
            {
                dal.UpdateDepositSeq(info);
            }
            catch
            {
                throw;
            }
        }

        public void DeleteDepositSeq(M_FIM_Receives info)
        {
            try
            {
                dal.DeleteDepositSeq(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdatePaySeq(M_FIM_Receives info)
        {
            try
            {
                dal.UpdatePaySeq(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateReceiptNo(M_FIM_Receives info)
        {
            try
            {
                dal.UpdateReceiptNo(info);
            }
            catch
            {
                throw;
            }
        }

        public DataTable PrintCheqe(DateTime RecieveDate)
        {
            return dal.PrintCheqe(RecieveDate);
        }

        public void UpdatePrintOut(int updated_by, DateTime? receive_date, int print_out, string receive_seq)
        {
            dal.UpdatePrintOut(updated_by, receive_date, print_out, receive_seq);
        }

        public DataTable PrintHAInvoice(DateTime RecieveDate)
        {
            return dal.PrintHAInvoice(RecieveDate);
        }
    }
}
